package com.interview.item.javabase.arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author:zxh
 * @Description: 数组复制演示，2中方法
 * @Date: 2020/3/23
 * @Modified By:
 */

public class ArraysCopy {

    private static final  Logger logger = LoggerFactory.getLogger(ArraysCopy.class);

    /**
     * @Author:zxh
     * @Description: 从arrayOne数组0索引下标开始，复制3个元素到arrayTwo的数组中索引从0开始
     * @Date: 2020/3/23
     */
    public static void systemCopy() {
        int[] arrayOne = {3, 4, 6, 7, 8, 9, 10};
        int[] arrayTwo = new int[3];
        System.arraycopy(arrayOne, 0, arrayTwo, 0, 3);
        for (int j = 0; j < arrayTwo.length; j++) {
            logger.info("输出："+arrayTwo[j]);
        }

    }

    /**
      * @Author:zxh
      * @Description: 从被复制的arrayOne数组中复制4个元素，到创建的一个新数组中；
      * @Date: 2020/3/23
      */
    public static void arrayCopy() {
        int[] arrayOne = {3, 4, 6, 7, 8, 9, 10};
        int[] arrayTwo = Arrays.copyOf(arrayOne, 4);
        for (int j = 0; j < arrayTwo.length; j++) {
            logger.info("输出："+arrayTwo[j]);
        }

    }

    /**
      * @Author:zxh
      * @Description: 数组，集合互转
      * @Date: 2020/3/25
      */
    public static void arrayList() {
        int[] arrayOne = {3, 4, 6, 7, 8, 9, 10};
        List<Integer> ints = Arrays.asList(23,23,34);
        for (Integer inte:ints
             ) {
            logger.info("集合：{}",inte);
        }

        ArrayList<Integer> integers = new ArrayList<>();
        integers.add(4);
        integers.add(90);
        Object[] objects = integers.toArray();
        for (int i = 0; i < objects.length; i++) {
            logger.info("数组：{}",objects[i]);
        }
    }

    public static void main(String[] args) {
        //ArraysCopy.arrayCopy();
        //arrayList();


    }

}
